//
//  VersionController.swift
//  OneMeeting
//
//  Created by zhangheng on 2019/8/9.
//  Copyright © 2019 www.zhangheng.com. All rights reserved.
//

import Foundation

class VersionController: NSViewController {
    
    var isCheck:Bool = false {
        didSet {
            self.noNewLab.isHidden = !isCheck
        }
    }
    
    override func loadView() {
        let view = NSView.init(frame: NSRect.init(x: 0, y: 0, width: kVersionWinWidth, height: kVersionWinHeight))
        self.view = view
    }
    
    override func viewWillAppear() {
        super.viewWillAppear()
        if let window = self.view.window {
            window.styleMask = [.titled,.closable,.fullSizeContentView]
            window.isMovable = true
            window.isMovableByWindowBackground = true
            window.titlebarAppearsTransparent = true
            window.titleVisibility = .hidden
            window.title = ""
        }
    }
    override func viewDidLoad() {
        super.viewDidLoad()
        self.setupUI()
        self.loadData()
    }
    
    func setupUI() {
        self.view.addSubview(logoImageV)
        logoImageV.snp.makeConstraints { (make) in
            make.width.height.equalTo(180)
            make.left.equalToSuperview().offset(20)
            make.centerY.equalToSuperview()
        }
        self.view.addSubview(rightView)
        rightView.snp.makeConstraints { (make) in
            make.left.equalTo(logoImageV.snp.right).offset(10)
            make.right.equalTo(-20)
            make.height.equalToSuperview()
            make.top.equalToSuperview()
        }
        
        self.rightView.addSubview(nameLab)
        nameLab.snp.makeConstraints { (make) in
            make.left.equalToSuperview()
            make.top.equalTo(logoImageV).offset(10)
            make.width.equalToSuperview()
            make.height.equalTo(60)
        }
        
        self.rightView.addSubview(versionLab)
        versionLab.snp.makeConstraints { (make) in
            make.left.equalToSuperview()
            make.top.equalTo(nameLab.snp.bottom).offset(0)
            make.height.equalTo(22)
        }
        
        self.rightView.addSubview(noNewLab)
        noNewLab.snp.makeConstraints { (make) in
            make.centerY.equalTo(versionLab)
            make.left.equalTo(versionLab.snp.right).offset(5)
        }
        
        self.rightView.addSubview(buildLab)
        buildLab.snp.makeConstraints { (make) in
            make.left.equalToSuperview()
            make.top.equalTo(versionLab.snp.bottom).offset(20)
            make.width.equalToSuperview()
            make.height.equalTo(18)
        }
        
        self.rightView.addSubview(buildLab2)
        buildLab2.snp.makeConstraints { (make) in
            make.left.equalToSuperview()
            make.top.equalTo(buildLab.snp.bottom).offset(0)
            make.width.equalToSuperview()
            make.height.equalTo(18)
        }
        
        
    }
    
    func loadData() {
        self.versionLab.stringValue = "版本 ".localized()+AppInfo.majorVersion()+"("+AppInfo.minorVersion()+")"
    }
    
    
    
    lazy var nameLab: NSLabel = {
        let lab = NSLabel.label(title: "\(AppInfo.appDisplayName())", textColor: color_main50, font: NSFont.systemFont(ofSize: 50))
        lab.alignment = .left
        lab.sizeToFit()
        return lab
    }()
    
    lazy var versionLab: NSLabel = {
        let lab = NSLabel.label(title: "版本".localized()+"1.0.0(15)", textColor: color_gray(100), font: NSFont.systemFont(ofSize: 18))
        lab.alignment = .left
        lab.sizeToFit()
        return lab
    }()
    
    lazy var noNewLab: NSLabel = {
        let lab = NSLabel.label(title: "(已经是最新版本)".localized(), textColor: color_gray(120), font: NSFont.systemFont(ofSize: 14))
        lab.isHidden = true
        lab.alignment = .left
        lab.sizeToFit()
        return lab
    }()
    
    lazy var buildLab: NSLabel = {
        let lab = NSLabel.label(title: "Copyright@2011-2019 "+"1meeting".localized()+" Inc.", textColor: color_gray(120), font: NSFont.systemFont(ofSize: 12))
        lab.sizeToFit()
        lab.alignment = .left
        return lab
    }()
    
    lazy var buildLab2: NSLabel = {
        let lab = NSLabel.label(title: "保留一切版权".localized(), textColor: color_gray(120), font: NSFont.systemFont(ofSize: 12))
        lab.sizeToFit()
        lab.alignment = .left
        return lab
    }()
    
    
    
    lazy var rightView: NSView = {
        let view = NSView.init()
        return view
    }()
    
    lazy var logoImageV: NSImageView = {
        let imageV = NSImageView.init(image: NSImage.init(named: NSImage.Name.init("ic_logo_blue"))!)
        return imageV
    }()
    
    @objc func closeBtnAction(senber:LLCustomBtn) -> () {
        NSApplication.shared.stopModal()
    }
}
